package com.zy.excel.test2;

import java.util.ArrayList;
import java.util.List;

/**
 * User: 11473
 * Date: 2019/10/22
 * Time: 9:30
 * Description: 将数组转换为bean实体类
 */
public class beanConverter {

    public static List<Student> listToStudentConverter(List<List<String>> lists){

        List<String> title = lists.get(0);

        //匹配读取的表格是否与bean一致
        if(! ("学号".equals(title.get(0)) && "姓名".equals(title.get(1)) && "年龄".equals(title.get(2)))){
            //如果不一致，则提示异常
            System.out.println("表格信息与bean不一致！");
            return null;
        }
        List<Student> students = new ArrayList<>();
        for (int i = 1; i < lists.size(); i++){
            List<String> list = lists.get(i);
            Student student = new Student();
            student.setId(Integer.parseInt(list.get(0)));
            student.setName(list.get(1));
            student.setAge(Integer.parseInt(list.get(2)));
            students.add(student);
        }
        return students;
    }

}